﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using lakethaiClassLibrary;

public partial class cms_products : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["serviceID"] == null)
            this.dvItem.DefaultMode = DetailsViewMode.Insert;
    }
    protected void dvItem_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        FileUpload fu = (FileUpload)dvItem.Rows[0].Cells[1].FindControl("fuPhoto");
        string url = @"../images/nophoto.gif";
        if (fu.HasFile)
        {
            try
            {
                url = myHelp.SaveImageFile(@"../upload/photo/", fu, 200);
            }
            catch { }
        }
        sdsItem.InsertParameters["photoURL"].DefaultValue = url;
    }
    protected void dvItem_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        FileUpload fu = (FileUpload)dvItem.Rows[0].Cells[1].FindControl("fuPhoto");
        Image img = (Image)dvItem.Rows[0].Cells[1].FindControl("imgPhoto");
        if (fu.HasFile)
        {
            if (img.ImageUrl.CompareTo(@"../images/nophoto.gif") != 0)
                myHelp.DeleteFile(img.ImageUrl);
            string url = string.Empty;
            try
            {
                url = myHelp.SaveImageFile(@"../upload/photo/", fu, 200);
            }
            catch { }
            sdsItem.UpdateParameters["photoURL"].DefaultValue = url;
        }
        else
        {
            sdsItem.UpdateParameters["photoURL"].DefaultValue = img.ImageUrl;
        }
    }
    protected void dvItem_ItemDeleting(object sender, DetailsViewDeleteEventArgs e)
    {
        Image img = (Image)dvItem.Rows[0].Cells[1].FindControl("imgPhoto");
        if (img.ImageUrl.CompareTo(@"../images/nophoto.gif") != 0)
            myHelp.DeleteFile(img.ImageUrl);
    }
}
